<template>
<a-input :value="text" v-bind="$attrs"  @change="inputChange">
    <my-icon slot="addonAfter" type="iconearth-full" @click="setLang"/>
</a-input>
</template>

<script>
/**
 * @Author : yangsanjin
 * @Date: 2024-10-24 15:20
 */
import {Dialog} from "@lowcode/jpaas-common-lib"
import {cloneDeep} from 'lodash-es'
export default {
    name: "RxLangInput",
    props:{
        value:{}
    },
    computed:{
        text(){
            let lang = window.localStorage.getItem('language') || 'zh-CN' ;
            return this.value[lang] ?? ''
        }
    },
    methods:{
        inputChange(e){
            let {value} = e.target ;
            let obj = cloneDeep(this.value);
            let lang = window.localStorage.getItem('language') || 'zh-CN' ;
            this.$emit('input',{
                ...obj,
                [lang]:value
            })
            this.$emit('change',e)
        },
        setLang(){
            let config = {
                curVm: this,
                widthHeight: ['500px', '380px'],
                data: {
                    i18nJson:this.value
                }
            }
            Dialog.openI18nDialog(config,  (action, data)=> {
                this.$emit('input',data)
            });
        }
    }
}
</script>

<style scoped>

</style>